package com.handpay.nocardpay.baselibrary.account.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.account.model.IGetVerificationCodeModel;
import com.handpay.nocardpay.baselibrary.account.model.bean.VerificationCodeBean;
import com.handpay.nocardpay.baselibrary.account.model.impl.GetVerificationCodeImpl;
import com.handpay.nocardpay.baselibrary.account.view.ISendVerfCodeView;
import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/17.
 */

public class VerfcodePresenterImpl implements IBasePresenter {
    private ISendVerfCodeView sendVerfCodeView;
    private Context mContext;
    private IGetVerificationCodeModel<VerificationCodeBean> verificationCode;

    public void setSendVerfCodeView(ISendVerfCodeView sendVerfCodeView) {
        this.sendVerfCodeView = sendVerfCodeView;
    }

    public VerfcodePresenterImpl(Context mContext) {
        this.mContext = mContext;
        this.verificationCode = new GetVerificationCodeImpl(mContext);
    }

    /**
     * 秒秒通获取验证码
     *
     * @param paramers
     * @param clzz
     * @param isShowLoading
     */
    public void getVerificationCode(HashMap<String, Object> paramers, Class<VerificationCodeBean> clzz, boolean isShowLoading) {
        verificationCode.getVerificationCode(paramers, clzz, new IBaseModel.OnRequestFinishedListener<VerificationCodeBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (sendVerfCodeView != null) {
                    sendVerfCodeView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(VerificationCodeBean response) {
                HPLog.d(HPLog.SSX_TAG, response.toString());
                if (sendVerfCodeView != null) {
                    sendVerfCodeView.showSendVerfCodeSuccess();
                }
            }
        });
    }




    @Override
    public void onDestory() {
        if (sendVerfCodeView != null) {
            sendVerfCodeView = null;
        }
    }
}
